﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Gizmox.WebGUI.Common.Resources;
using Gizmox.WebGUI.Forms;

namespace TVC
{
    [Serializable()]
    public class NavigationCategoryNode : CategoryNode
    {
        private TreeView mobjTreeView = null;
        private BaseForm mobjBaseForm = null;

        public NavigationCategoryNode(BaseForm objBaseForm, NavigationTabs objTabs, string strLabel, string module, string address, string language)
            : this(objBaseForm, objTabs, strLabel, module, "24X24.Folders.gif", address, language)
        {

        }

        public NavigationCategoryNode(BaseForm objBaseForm, NavigationTabs objTabs, string strLabel, string module, string strIcon, string address, string language)
            : base(null, strLabel, address, language)
        {
            mobjBaseForm = objBaseForm;

            NavigationTab objTab = new NavigationTab(strLabel);
            objTab.Text = clsConfigurarion.GetLabel(address, "", strLabel, language);
            objTab.Name = address;
            Address = address;
            Language = language;
            objTab.Image = new IconResourceHandle(strIcon);
            mobjTreeView = new TreeView();
            mobjTreeView.Dock = DockStyle.Fill;
            mobjTreeView.BorderStyle = BorderStyle.None;
            mobjTreeView.AfterSelect += new TreeViewEventHandler(mobjTreeView_AfterSelect);
            mobjTreeView.NodeMouseClick += new TreeNodeMouseClickEventHandler(mobjTreeView_NodeMouseClick);
            objTab.Controls.Add(mobjTreeView);

            objTabs.TabPages.Add(objTab);
        }

        void mobjTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            mobjTreeView.AfterSelect -= new TreeViewEventHandler(mobjTreeView_AfterSelect);
            mobjBaseForm.SelectCategory(e.Node.Tag as CategoryNode, "", true);
            //mobjTreeView.AfterSelect += new TreeViewEventHandler(mobjTreeView_AfterSelect);
        }



        private void mobjTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            mobjBaseForm.SelectCategory(e.Node.Tag as CategoryNode, "", true);

        }

        public override TreeNodeCollection Nodes
        {
            get
            {
                return mobjTreeView.Nodes;
            }
        }
    }

}
